import axios from '../axios';

// 基础API路径
const API_PREFIX = '/api';
const ADMIN_PREFIX = `${API_PREFIX}/admin`;
const SETTINGS_PREFIX = `${API_PREFIX}/settings`;

// 视频相关API
export const videoAPI = {
  getList: (params) => axios.get(`${API_PREFIX}/videos`, { params }),
  getDetail: (id) => axios.get(`${API_PREFIX}/videos/${id}`),
  getComments: (id, params) => axios.get(`${API_PREFIX}/videos/${id}/comments`, { params }),
  getInteraction: (id) => axios.get(`${API_PREFIX}/videos/${id}/interaction`),
  upload: (formData) => axios.post(`${API_PREFIX}/videos/upload`, formData),
  update: (id, data) => axios.put(`${API_PREFIX}/videos/${id}`, data),
  delete: (id) => axios.delete(`${API_PREFIX}/videos/${id}`)
};

// 管理员API
export const adminAPI = {
  // 仪表盘
  getStats: () => axios.get(`${ADMIN_PREFIX}/stats`),
  getTrendStats: (params) => axios.get(`${ADMIN_PREFIX}/stats/trend`, { params }),
  getActivities: () => axios.get(`${ADMIN_PREFIX}/activities`),

  // 用户管理
  getUsers: (params) => axios.get(`${ADMIN_PREFIX}/users`, { params }),
  updateUserStatus: (id, status) => axios.put(`${ADMIN_PREFIX}/users/${id}/status`, { status }),
  updateUserRole: (id, role) => axios.put(`${ADMIN_PREFIX}/users/${id}/role`, { role }),
  deleteUser: (id) => axios.delete(`${ADMIN_PREFIX}/users/${id}`),
  // 批量操作用户
  batchEnableUsers: (userIds) => axios.post(`${ADMIN_PREFIX}/users/batch-enable`, { userIds }),
  batchDisableUsers: (userIds) => axios.post(`${ADMIN_PREFIX}/users/batch-disable`, { userIds }),

  // 视频管理
  getVideos: (params) => axios.get(`${ADMIN_PREFIX}/videos`, { params }),
  updateVideo: (id, data) => axios.put(`${ADMIN_PREFIX}/videos/${id}`, data),
  updateVideoStatus: (id, status) => axios.put(`${ADMIN_PREFIX}/videos/${id}/status`, { status }),
  deleteVideo: (id) => axios.delete(`${ADMIN_PREFIX}/videos/${id}`),

  // 帖子管理
  getPosts: (params) => axios.get(`${ADMIN_PREFIX}/posts`, { params }),
  updatePostStatus: (id, status) => axios.put(`${ADMIN_PREFIX}/posts/${id}/status`, { status }),
  deletePost: (id) => axios.delete(`${ADMIN_PREFIX}/posts/${id}`),

  // 评论管理
  getComments: (params) => axios.get(`${ADMIN_PREFIX}/comments`, { params }),
  updateCommentStatus: (id, status) => axios.put(`${ADMIN_PREFIX}/comments/${id}/status`, { status }),
  deleteComment: (id) => axios.delete(`${ADMIN_PREFIX}/comments/${id}`),

  // 分类管理
  getCategories: (params) => axios.get(`${ADMIN_PREFIX}/categories`, { params }),
  createCategory: (data) => axios.post(`${ADMIN_PREFIX}/categories`, data),
  updateCategory: (id, data) => axios.put(`${ADMIN_PREFIX}/categories/${id}`, data),
  deleteCategory: (id) => axios.delete(`${ADMIN_PREFIX}/categories/${id}`)
};

// 设置API
export const settingsAPI = {
  // 基本设置
  getBasicSettings: () => axios.get(`${SETTINGS_PREFIX}/basic`),
  updateBasicSettings: (data) => axios.put(`${SETTINGS_PREFIX}/basic`, data),

  // 邮件设置
  getEmailSettings: () => axios.get(`${SETTINGS_PREFIX}/email`),
  updateEmailSettings: (data) => axios.put(`${SETTINGS_PREFIX}/email`, data),

  // 存储设置
  getStorageSettings: () => axios.get(`${SETTINGS_PREFIX}/storage`),
  updateStorageSettings: (data) => axios.put(`${SETTINGS_PREFIX}/storage`, data),

  // 维护备份
  getBackups: () => axios.get(`${SETTINGS_PREFIX}/maintenance/backups`),
  createBackup: () => axios.post(`${SETTINGS_PREFIX}/maintenance/backups`),
  restoreBackup: (backupId) => axios.post(`${SETTINGS_PREFIX}/maintenance/backups/${backupId}/restore`),
  deleteBackup: (backupId) => axios.delete(`${SETTINGS_PREFIX}/maintenance/backups/${backupId}`)
};

export default {
  videoAPI,
  adminAPI,
  settingsAPI
};